﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 所有界面基类。有底图的对话框
/// </summary>
public abstract class Dialog
{
    protected GameObject _uiRoot;

    Button _btnClose;

    protected GameObject LoadUI(string uiRootPath)
    {
        _uiRoot = UIManager.instance.AddUI(uiRootPath);

        _btnClose = _uiRoot.FindComponent<Button>("BtnClose");
        if (_btnClose != null)
        {
            _btnClose.onClick.AddListener(OnBtnCloseClick);
        }

        return _uiRoot;
    }

    /// <summary>
    /// 各个对话框可以重写
    /// </summary>
    protected virtual void OnBtnCloseClick()
    {
        DialogMgr.instance.Close(this);
    }

    public void Close()
    {
        UIManager.instance.RemoveUI(_uiRoot);
    }
}
